
const state = {
  tabsOption: [{
    route: "/dashboard",
    title: "首页",
    name: "首页"
  }],
  tabsCurrentIndex: "/dashboard"
};
const mutations = {
  ADD_TAB: (state, data) => {
    state.tabsOption.push(data);
  },
  DELETE_TAB: (state, route) => {
    const index = state.tabsOption.findIndex((tab) => tab.route === route);
    state.tabsOption.splice(index, 1);
  },
  SET_TAB: (state, index) => {
    state.tabsCurrentIndex = index;
  },
  CLEAR_TAB: (state) => {
    // 初始化tab
    state.tabsOption = [{
      route: "/dashboard",
      title: "首页",
      name: "首页"
    }];
  }
};

const actions = {
  addTab({ state, commit }, tab) {
    // 超出一定长度后删除一个在进行添加
    if (state.tabsOption.length > 8) {
      state.tabsOption.splice(1, 1);
    }
    commit("ADD_TAB", tab);
  }
};

export default {
  namespaced: true,
  state,
  mutations,
  actions
};
